//
//  MoreCommentTableViewCell.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2018/1/19.
//  Copyright © 2018年 Lwx. All rights reserved.
//

#import "MoreCommentTableViewCell.h"
@interface MoreCommentTableViewCell()
@property (nonatomic, strong)UIView * borderView;
@property (nonatomic, strong)UIImageView * iconImage;
@property (nonatomic, strong)UILabel * nameLab;
@property (nonatomic, strong)UILabel * dateLab;
@property (nonatomic, strong)UILabel * contentLab;
@property (nonatomic, strong)UIImageView * picLeft;
@property (nonatomic, strong)UIImageView * picMiddle;
@property (nonatomic, strong)UIImageView * picRight;
@end
@implementation MoreCommentTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        
        [self.contentView addSubview:self.borderView];
        [self.contentView addSubview:self.iconImage];
        [self.contentView addSubview:self.nameLab];
        [self.contentView addSubview:self.dateLab];
        [self.contentView addSubview:self.contentLab];
        [self.contentView addSubview:self.picLeft];
        [self.contentView addSubview:self.picMiddle];
        [self.contentView addSubview:self.picRight];
    }return self;
}

- (UIView *)borderView{
    if (!_borderView) {
        _borderView = [[UIView alloc] init];
        _borderView.backgroundColor = getColor(bgColor);
    }return _borderView;
}

- (UIImageView *)iconImage{
    if (!_iconImage) {
        _iconImage = [[UIImageView alloc] init];
    }return _iconImage;
}

- (UILabel *)nameLab{
    if (!_nameLab) {
        _nameLab = [[UILabel alloc] init];
        _nameLab.font = DEF_FontSize_14;
        _nameLab.textColor = [UIColor blackColor];
        _nameLab.textAlignment = NSTextAlignmentLeft;
    }return _nameLab;
}

- (UILabel *)dateLab{
    if (!_dateLab) {
        _dateLab = [[UILabel alloc] init];
        _dateLab.font = DEF_FontSize_12;
        _dateLab.textColor = [UIColor grayColor];
        _dateLab.textAlignment = NSTextAlignmentLeft;

    }return _dateLab;
}

- (UILabel *)contentLab{
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] init];
        _contentLab.font = DEF_FontSize_14;
        _contentLab.textColor = [UIColor blackColor];
        _contentLab.textAlignment = NSTextAlignmentLeft;
        _contentLab.numberOfLines = 0;
        _contentLab.lineBreakMode = NSLineBreakByWordWrapping;
    }return _contentLab;
}

- (UIImageView *)picLeft{
    if (!_picLeft) {
        _picLeft = [[UIImageView alloc] init];
    }return _picLeft;
}

- (UIImageView *)picMiddle{
    if (!_picMiddle) {
        _picMiddle = [[UIImageView alloc] init];
    }return _picMiddle;
}

- (UIImageView *)picRight{
    if (!_picRight) {
        _picRight = [[UIImageView alloc] init];
    }return _picRight;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    int border = 10;
    int labH = 15;
    self.borderView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 5);
    int iconImageW = 30;
    self.iconImage.frame = CGRectMake(border, self.borderView.bottom + border, iconImageW, iconImageW);
    self.nameLab.frame = CGRectMake(self.iconImage.right + border, self.iconImage.top, SCREEN_WIDTH - self.iconImage.right - border*2, labH);
    self.dateLab.frame = CGRectMake(self.nameLab.left, self.nameLab.bottom, self.nameLab.width, labH);
    if ([self.delegate respondsToSelector:@selector(getLabelHeightWithText:width:font:)]) {
        CGFloat contentLabH = [self.delegate getLabelHeightWithText:self.contentLab.text width:SCREEN_WIDTH - 2*border font:14];
        self.contentLab.frame = CGRectMake(self.iconImage.left, self.iconImage.bottom + border, SCREEN_WIDTH - 2*border, contentLabH);
    }
    int picW = (SCREEN_WIDTH - 4*border)/3;
    int picH = 100;
    self.picLeft.frame = CGRectMake(border, self.contentLab.bottom + border, picW, picH);
    self.picMiddle.frame = CGRectMake(self.picLeft.right + border, self.picLeft.top, self.picLeft.width, self.picLeft.height);
    self.picRight.frame = CGRectMake(self.picMiddle.right + border, self.picLeft.top, self.picLeft.width, self.picLeft.height);
}

- (void)setModelData:(VisitorCommentCellModelData *)modelData{
    _modelData = modelData;
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:modelData.avatar]];
    self.nameLab.text = modelData.nickname;
    self.dateLab.text = modelData.addtime;
    self.contentLab.text = modelData.content;
    if (modelData.pic1 != nil && modelData.pic1.length > 0) {

        self.picLeft.hidden = NO;
        self.picMiddle.hidden = NO;
        self.picRight.hidden = NO;

        [self.picLeft sd_setImageWithURL:[NSURL URLWithString:modelData.pic1]];
        [self.picMiddle sd_setImageWithURL:[NSURL URLWithString:modelData.pic2]];
        [self.picRight sd_setImageWithURL:[NSURL URLWithString:modelData.pic3]];
    }else{

        self.picLeft.hidden = YES;
        self.picMiddle.hidden = YES;
        self.picRight.hidden = YES;
    }
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
